<?php
namespace Home\Model;

class RegionModel extends \Common\Model\CommonModel{
    
    //获取机构ID（agency_id）
    public function get_agency_by_regions($regions){
        if (!is_array($regions) || empty($regions))return 0;
        $arr = array();
        $res = $this->field('region_id, agency_id')->where("region_id in(".implode(',', $regions).") AND region_id > 0 AND agency_id > 0")->select();
        foreach ($res as $val){
            $arr[$val['region_id']] = $val['agency_id'];
        }
        if (empty($arr)) return 0;
    
        $agency_id = 0;
        for ($i = count($regions) - 1; $i >= 0; $i--)
        {
            if (isset($arr[$regions[$i]]))
            {
                return $arr[$regions[$i]];
            }
        }
    }
}